<?php
namespace app\home\controller;
use think\Db;
use think\captcha\Captcha;
use think\Loader;
class Liuyan extends \think\Controller{
    public function liuyan(){
       

        $id=$_GET['id'];
        $list=db('article')->where('id',$id)->select();

        $data=array();
        foreach($list as $val){
            $img=json_decode($val['img'],true);
            if($img!=NULL){
                $val['img']=$img;
            }
            $data[]=$val;
        }
        $this->assign('list',$data);

        // $this->assign('list',$list);
        return $this->fetch('liuyan');//继承基类的控制器 
    }
    public function upload(){
        $file=request()->file('img');
            if($file){
                $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
                if($info){
                    $path=$info->getSaveName();
                    $img_src="/uploads/".$path;
                    echo $img_src;
                }else{
                    //	上传失败获取错误信息
                    $this->error($file->getError());
                }
            }
            else{
                $this->error("必须上传图片");
            }
    }
    public function addCommit(){
        $content=input('param.content','','htmlspecialchars');
        $badword=array(
            '习大大','垃圾','草',
        );
        $badword1 = array_combine($badword,array_fill(0,count($badword),'*'));
        $bb = $content;
        $data['content']= strtr($bb, $badword1);
        
        $data['time']=time();

        $ret=db('liuyan')->insert($data);
    }
    public function contentList(){
        $pageno=input('post.pageno');
        $pagesize=7;
        $left=($pageno-1)*$pagesize;
        $content=db('liuyan')->limit("{$left},{$pagesize}")->select();
        if(empty($content)){
            $this->error('没有数据了','','');
        }
        for($i=0;$i<count($content);$i++){
            $content[$i]['content']=htmlspecialchars_decode($content[$i]['content']);
        }
        $this->success('ok','',$content);
            // return $content;
    }

    public function upload1(){
        $file=request()->file('img');
            if($file){
                $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
                if($info){
                    $path=$info->getSaveName();
                    $img_src="/uploads/".$path;
                    echo $img_src;
                }else{
                    //	上传失败获取错误信息
                    $this->error($file->getError());
                }
            }
            else{
                $this->error("必须上传图片");
            }
    }
    public function addHuifu(){
        $data['huifucontent']=input('param.huifu','','htmlspecialchars');
        $data['times']=time();
        $ret=db('huifu')->insert($data);
    }
    public function huifuList(){
        // $data['user_id']=input('param.user_id','','htmlspecialchars');
        $pageno=input('post.pageno');
        $pagesize=3;
        $left=($pageno-1)*$pagesize;
       
        $content=db('huifu')->limit("{$left},{$pagesize}")->select();
        if(empty($content)){
            $this->error('没有数据了','','');
        }
        for($i=0;$i<count($content);$i++){
            $content[$i]['huifucontent']=htmlspecialchars_decode($content[$i]['huifucontent']);
        }
        $this->success('ok','',$content);
            // return $content;
    }


    // public function zan(){
    //     $article_id=$_GET['id'];
    //     $user_id=session('user_id');
    //     $getdata=$this->data_model;
    //     $data=$getdata->get_vote_ip($article_id,$user_id);
    //     $msg="";
    //     if(empty($data['article_id']) || !$data['user_id']){
    //     　　$data=array('article_id'=>$article_id,'vote'=>1,'user_id'=>$user_id);
    //     　　$re=$getdata->insert_zan($data);
    //     　　$msg.="点赞成功";
    //     }else{
    //     　　$msg.="一个id只能操作一次";
    //     }
    //     echo $msg;
    //     }
    // }
}